import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import components from "unplugin-vue-components/vite";
import { VarletUIResolver } from "unplugin-vue-components/resolvers";
import { VantResolver } from "unplugin-vue-components/resolvers";
// @ts-ignore
import path from "path";
const srcPath = path.resolve(__dirname, "src");
export default defineConfig({
  plugins: [
    vue(),
    components({
      resolvers: [VarletUIResolver(), VantResolver()],
    }),
  ],
  base: "./",
  resolve: {
    alias: [{ find: "@", replacement: srcPath }],
  },
  server: {
    host: "0.0.0.0", // 本机的局域网IP
    port: 3001,
    proxy: {
      "/web": {
        // target: "http://47.104.71.122:8088", // 接口基地址
        target: "http://127.0.0.1:8088", // 接口基地址
        // changeOrigin: true,
        rewrite: (path) => {
          console.log(path, "vite"); // 打印[/api/userInfo] 这就是http-proxy要请求的url,我们基地址实际是没有/api 所以replace掉
          return path.replace(/^\/web/, "");
        },
      },
    },
  },
});
